home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / progrmng / intcdvpc.sit / INIT_cdev IPC README / INIT_cdev IPC README
Encoding:
Text File  |  1990-09-17  |  6.7 KB  |  125 lines  |  [TEXT/MPS ]

  1. # INIT developer helper and IPC example. Version 2.0
  2. #  ⌐ Copyright 1990 Jeremy Grodberg.  All Rights Reserved
  3. #
  4. #    Development system: MPW 3.1 
  5. #
  6. # Unmodified copies of this source and object code may be distributed free of charge.
  7. # Adaptations of this code for other development systems may be made and distributed
  8. # as part of said development system, otherwise, neither this code not adaptations of
  9. # it may be distributed along with other products for which a fee is charged.
  10. #
  11. # Apple Computer, Inc. is specifically granted non-exclusive permission to distribute 
  12. # this code by any means, either for free, or with other code for which a fee is 
  13. # charged, provided they do not impose further restrictions on its use, and they
  14. # include this entire copyright notice.
  15. # This source is provided to make writing INITs and cdevs a little easier.  
  16. # RegisterMySignature can also be helpful to anyone who wants to install a DRVR.
  17. # If you find it helpful, please send me a copy of your finished product.
  18. #
  19. # THIS SOURCE IS PROVIDE AS IS, AND ALL WARRANTIES ARE EXPLICITY DISCLAIMED.
  20. # BY USING THIS WORK, THE USER AGREES TO ASSUME ALL RESPONSIBILITY FOR 
  21. # DAMAGES THAT MAY ARISE AS A RESULT, AND TO PROTECT FROM HARM ALL ENTITIES
  22. # INVOLVED IN THE CREATION AND DISTRIBUTION OF THIS WORK.
  23. #
  24. # Jeremy Grodberg.  September, 1990
  25. # jgro@lia.com  (via AppleLink: jgro@lia.com@INTERNET#)
  26. # America Online: jgro (I don't read this very often)
  27.  
  28. * Changes since Version 1.0:  Support for systems that do not support Gestalt
  29.  
  30.  
  31. * This is a library of code which you can use to share memory across processes.
  32. * While you could use this for any kind of inter-process communication, it is
  33. * especially intended to allow a control panel (cdev) to alter the behavior
  34. * of a startup document (INIT) while the latter is running (that is, without
  35. * restarting the computer).  Entry points are defined as a Pascal functions so 
  36. * you can call it from an Application if you want to.
  37. *
  38. * The theory behind this is that your INIT will have a block of variables which 
  39. * it needs to use for various purposes, including storing user options.
  40. * The user options would be stored in a resource which is a copy of the
  41. * INIT's variables, and could be edited by a Control Panel Device (cdev).
  42. * At INIT time, the (edited) resource is copied into the INIT's variables for 
  43. * the INIT to use.  In other words, to change the user options, the user uses
  44. * the cdev to edit the resource, which will change the options the next time the
  45. * INIT is loaded.
  46. * This is how most INITs are written, and this is why most INITs require a 
  47. * reboot for changes to take effect.  Before now, there was no simple way
  48. * for a cdev to get a hold of the INITs variables, so it could only communicate by
  49. * changing the resource and then reinitializing the INIT.
  50. *
  51. * Now with RegisterMySignature, your INIT can register itself and provide a pointer to 
  52. * anyone that wants it.  RegisterMySignature takes a selector which is an OSType, and
  53. * returns a longint.  For your INIT, you register your INIT's creator bytes 
  54. * (which you have cleared with Apple by registering with MacDTS) and whatever
  55. * longint you want, presumably the pointer to your INIT's variables. Later,
  56. * your cdev will call LookupMySignature with your INITs creator bytes, and get back
  57. * the pointer to the variables, so they can be changed in real time.  It will
  58. * also be able to tell if the INIT was not installed, because the creator bytes
  59. * will not be registered.  See the accompanying SampleLookup.c for an example.
  60. *
  61. * On systems that support Gestalt (System 6.0.4 and later), Gestalt is used to 
  62. * do the actual registration and lookup.  On older systems, a driver (DRVR) is 
  63. * installed which will do the registration.  The driver's source code is not
  64. * included, but the DRVR resource is. You don't need to do anything with the driver
  65. * but include it in your INIT.  RegisterMySignature and LookupMySignature take
  66. * care of everything automatically.
  67. *
  68. * For an excellent start on how to write INITs, 
  69. * read Technote #256, August 1990 revsion.
  70.  
  71.  
  72. # This package contains 6 files besides this one.  
  73. #        SampleINIT.a is an INIT which you can use as a template for your own INITs
  74. #        RegisterMySignature.c registers a signature and longint for later lookup by the 
  75. #            same or another process.  It uses Gestalt if available, or installs the Driver 
  76. #         contained in IPCDriver.rsrc and uses that.  The Driver must be in a resource
  77. #            file that is open when RegisterMySignature is called (such as the the INIT
  78. #            file which calls RegisterMySignature).  RegisterMySignature
  79. #            also can be used to pass the address of shared memory between multiple
  80. #            processes, making Inter-Process Communication available right now.
  81. #        RegisterWithGestalt.a is a utility function which uses Gestalt to register the
  82. #            address of the INIT's globals, for use by the INIT's cdev.  
  83. #        LookupMySignature.c contains LookupMySignature(), which is the library entry 
  84. #            for looking up the data registered by RegisterMySignature. LookupMySignature.c
  85. #            also contains AskGestalt.c, which is the utility corresponding to 
  86. #            RegisterWithGestalt, and which is called automatically by LookupMySignature().
  87. #        SampleLookup.c shows a very simple example of how you would use LookupMySignature
  88. #            to get the address of the INIT's (or IPC's) memory.
  89. #        IPCDriver.rsrc contains the DRVR resource which does the register and lookup
  90. #            on systems that don't support Gestalt.  The driver must be copied into any 
  91. #            executable file (Application, INIT, etc.) which calls RegisterMySignature.
  92. #     The driver must be named "..ipc by jgro" and should have its SystemHeap
  93. #            flag set.
  94.  
  95. # To compile and link SampleINIT as provided, you need to have a copy of ShowINIT
  96. # already compiled.  ShowINIT is on the Developer CD, and available elsewhere.
  97. # If you don't have a copy of ShowINIT, you can make the changes noted in 
  98. # SampleINIT.a and remove ShowINIT.a.o from the link line.
  99.  
  100.  
  101.  
  102.  
  103. # Execute the lines below to compile and link the SampleINIT.  Note that SampleINIT
  104. # doesn't do anything useful, so there's not much point in installing it.
  105. # Uncomment the -l to get a listing in <sourcefile>.lst
  106.  
  107. C -b2 LookupMySignature.c
  108. C -b2 RegisterMySignature.c 
  109. Asm RegisterWithGestalt.a -o RegisterWithGestalt.a.o    # -l -font monaco,9 
  110. Asm SampleINIT.a -o SampleINIT.a.o   # -l -font monaco,9 
  111.      
  112. Link SampleINIT.a.o ShowINIT.a.o RegisterMySignature.c.o ╢
  113.         RegisterWithGestalt.a.o "{Libraries}Interface.o" ╢
  114.         -o SampleINIT ╢
  115.         -m SAMPLE -sg SampleINIT -rt INIT=1  -t 'INIT' -c '????'
  116.  
  117.  
  118. # your cdev's link line would look something like this:
  119. #Link YourCdev.c.o SampleINIT.a.o LookupMySignature.c.o  ╢
  120. #        "{Libraries}Interface.o" ╢
  121. #        -o SampleINIT ╢
  122. #        -m YourCdevEntrypoint -sg YourCdevName -rt cdev=1  -t 'cdev' -c '????'
  123.